%%TORQ_GULFWAR_ELAS.m
% This program is part of the data and code used in:
% Kenneth R. Ahern, "Do Common Stocks Have Perfect Substitutes? 
% Product Market Competition and the Elasticity of Demand for Stocks," 
% The Review of Economics and Statistics, October 2014, 96(4):756-766.

% Gulf War Natural Experiment
% Oil stocks are    Name                Permno      SIC    
%                   Exxon               11850       2911
%                   Schlumberger        14277       1389
%                   Dresser             19254       1382
% Event day  January 17th, 1991 Fighting begins
% Day 53 in sample
clear all
load(['TORQPANEL.mat'])
INDE=find(TORQPANEL(:,2)==11850); % find Exxon observations
INDS=find(TORQPANEL(:,2)==14277); % find Schlumberger observations
INDD=find(TORQPANEL(:,2)==19254); % find Dresser observations
INDO=setdiff([1:9072]',[INDE;INDS;INDD]);  % all other firm-dates
ELASOIL=nanmean([TORQPANEL(INDE,8) TORQPANEL(INDS,8) TORQPANEL(INDD,8)],2); %aggregate stock price elasticity of oil stocks
RETOIL=nanmean([TORQPANEL(INDE,12) TORQPANEL(INDS,12) TORQPANEL(INDD,12)],2)-TORQPANEL(1:63,17)/100-TORQPANEL(1:63,16)/100; %abnormal returns of oil stocks
ELASOTH=nanmean(reshape(TORQPANEL(INDO,8),63,141),2); % aggregate stock price elasticity of non-oil stocks
RETOTH=nanmean(reshape(TORQPANEL(INDO,12),63,141),2)-TORQPANEL(1:63,17)/100-TORQPANEL(1:63,16)/100; %abnormal returns of non-oil stocks

%% Figure 2
plot([ELASOTH ELASOIL])

%% Table 5
% Find pre-period
INDEPRE=find((TORQPANEL(:,2)==11850)&(TORQPANEL(:,5)<53)); % find Exxon days in pre period
INDSPRE=find((TORQPANEL(:,2)==14277)&(TORQPANEL(:,5)<53)); % find Schlumber in pre period
INDDPRE=find((TORQPANEL(:,2)==19254)&(TORQPANEL(:,5)<53)); % find Dresser in pre period
INDOPRE=setdiff(find(TORQPANEL(:,5)<53),[INDEPRE;INDSPRE;INDDPRE]); % all other firm-dates in pre period

% Elasticity, returns, spreads, and turnover of oil stocks in pre-period
ELASOILPRE=nanmean([TORQPANEL(INDEPRE,8) TORQPANEL(INDSPRE,8) TORQPANEL(INDDPRE,8)],2); %stock price elasticity of oil stocks in pre period
RETOILPRE=nanmean([TORQPANEL(INDEPRE,12) TORQPANEL(INDSPRE,12) TORQPANEL(INDDPRE,12)],2)-TORQPANEL(1:52,17)/100-TORQPANEL(1:52,16)/100; % abnormal returns of oil stocks in pre period
PBASOILPRE=nanmean([TORQPANEL(INDEPRE,11) TORQPANEL(INDSPRE,11) TORQPANEL(INDDPRE,11)],2); % proportional bid-ask spread of oil stocks in pre period
TURNOILPRE=nanmean([TORQPANEL(INDEPRE,15) TORQPANEL(INDSPRE,15) TORQPANEL(INDDPRE,15)],2); % turnover of oil stocks in pre period

% Elasticity, returns, spreads, and turnover of non-oil stocks in pre-period
ELASOTHPRE=nanmean(reshape(TORQPANEL(INDOPRE,8),52,141),2);
RETOTHPRE=nanmean(reshape(TORQPANEL(INDOPRE,12),52,141),2)-TORQPANEL(1:52,17)/100-TORQPANEL(1:52,16)/100;
PBASOTHPRE=nanmean(reshape(TORQPANEL(INDOPRE,11),52,141),2);
TURNOTHPRE=nanmean(reshape(TORQPANEL(INDOPRE,15),52,141),2);

% Find post-period
INDEPOST=find((TORQPANEL(:,2)==11850)&(TORQPANEL(:,5)>=53));
INDSPOST=find((TORQPANEL(:,2)==14277)&(TORQPANEL(:,5)>=53));
INDDPOST=find((TORQPANEL(:,2)==19254)&(TORQPANEL(:,5)>=53));
INDOPOST=setdiff(find(TORQPANEL(:,5)>=53),[INDEPOST;INDSPOST;INDDPOST]); % all other firm-dates

% Elasticity, returns, spreads, and turnover of oil stocks in post-period
ELASOILPOST=nanmean([TORQPANEL(INDEPOST,8) TORQPANEL(INDSPOST,8) TORQPANEL(INDDPOST,8)],2);
RETOILPOST=nanmean([TORQPANEL(INDEPOST,12) TORQPANEL(INDSPOST,12) TORQPANEL(INDDPOST,12)],2)-TORQPANEL(53:63,17)/100-TORQPANEL(53:63,16)/100;
PBASOILPOST=nanmean([TORQPANEL(INDEPOST,11) TORQPANEL(INDSPOST,11) TORQPANEL(INDDPOST,11)],2);
TURNOILPOST=nanmean([TORQPANEL(INDEPOST,15) TORQPANEL(INDSPOST,15) TORQPANEL(INDDPOST,15)],2);

% Elasticity, returns, spreads, and turnover of non-oil stocks in post-period
ELASOTHPOST=nanmean(reshape(TORQPANEL(INDOPOST,8),11,141),2);
RETOTHPOST=nanmean(reshape(TORQPANEL(INDOPOST,12),11,141),2)-TORQPANEL(53:63,17)/100-TORQPANEL(53:63,16)/100;
PBASOTHPOST=nanmean(reshape(TORQPANEL(INDOPOST,11),11,141),2);
TURNOTHPOST=nanmean(reshape(TORQPANEL(INDOPOST,15),11,141),2);

%% RESULTS
%% Panel A - Stock price elasticity
[nanmean(ELASOILPRE) nanmean(ELASOILPOST) nanmean(ELASOILPOST)-nanmean(ELASOILPRE)]
[nanmean(ELASOTHPRE) nanmean(ELASOTHPOST) nanmean(ELASOTHPOST)-nanmean(ELASOTHPRE)]
[nanmean(ELASOILPRE)-nanmean(ELASOTHPRE) nanmean(ELASOILPOST)-nanmean(ELASOTHPOST) (nanmean(ELASOILPOST)-nanmean(ELASOILPRE))-(nanmean(ELASOTHPOST)-nanmean(ELASOTHPRE))]

%% compute ttests
[a b c d]=ttest2(ELASOILPRE,ELASOILPOST,[],[],'unequal')
[a b c d]=ttest2(ELASOTHPRE,ELASOTHPOST,[],[],'unequal')
[a b c d]=ttest2(ELASOILPRE,ELASOTHPRE,[],[],'unequal')
[a b c d]=ttest2(ELASOILPOST,ELASOTHPOST,[],[],'unequal')
%diff in diff
[a b c d]=ttest2((ELASOILPRE-ELASOTHPRE),(ELASOILPOST-ELASOTHPOST),[],[],'unequal')

%% Panel B - Daily returns
[100*nanmean(RETOILPRE) 100*nanmean(RETOILPOST) 100*nanmean(RETOILPOST)-100*nanmean(RETOILPRE)]
[100*nanmean(RETOTHPRE) 100*nanmean(RETOTHPOST) 100*nanmean(RETOTHPOST)-100*nanmean(RETOTHPRE)]
[100*nanmean(RETOILPRE)-100*nanmean(RETOTHPRE) 100*nanmean(RETOILPOST)-100*nanmean(RETOTHPOST) (100*nanmean(RETOILPOST)-100*nanmean(RETOILPRE))-(100*nanmean(RETOTHPOST)-100*nanmean(RETOTHPRE))]

%% compute ttests
[a b c d]=ttest2(RETOILPRE,RETOILPOST,[],[],'unequal')
[a b c d]=ttest2(RETOTHPRE,RETOTHPOST,[],[],'unequal')
[a b c d]=ttest2(RETOILPRE,RETOTHPRE,[],[],'unequal')
[a b c d]=ttest2(RETOILPOST,RETOTHPOST,[],[],'unequal')
%diff in diff
[a b c d]=ttest2((RETOILPRE-RETOTHPRE),(RETOILPOST-RETOTHPOST),[],[],'unequal')

%% Panel C - Proportional Bid-Ask Spreads
[100*nanmean(PBASOILPRE) 100*nanmean(PBASOILPOST) 100*nanmean(PBASOILPOST)-100*nanmean(PBASOILPRE)]
[100*nanmean(PBASOTHPRE) 100*nanmean(PBASOTHPOST) 100*nanmean(PBASOTHPOST)-100*nanmean(PBASOTHPRE)]
[100*nanmean(PBASOILPRE)-100*nanmean(PBASOTHPRE) 100*nanmean(PBASOILPOST)-100*nanmean(PBASOTHPOST) (100*nanmean(PBASOILPOST)-100*nanmean(PBASOILPRE))-(100*nanmean(PBASOTHPOST)-100*nanmean(PBASOTHPRE))]

%% compute ttests
[a b c d]=ttest2(PBASOILPRE,PBASOILPOST,[],[],'unequal')
[a b c d]=ttest2(PBASOTHPRE,PBASOTHPOST,[],[],'unequal')
[a b c d]=ttest2(PBASOILPRE,PBASOTHPRE,[],[],'unequal')
[a b c d]=ttest2(PBASOILPOST,PBASOTHPOST,[],[],'unequal')
%diff in diff
[a b c d]=ttest2((PBASOILPRE-PBASOTHPRE),(PBASOILPOST-PBASOTHPOST),[],[],'unequal')

%% Panel D - Turnover
[nanmean(TURNOILPRE) nanmean(TURNOILPOST) nanmean(TURNOILPOST)-nanmean(TURNOILPRE)]
[nanmean(TURNOTHPRE) nanmean(TURNOTHPOST) nanmean(TURNOTHPOST)-nanmean(TURNOTHPRE)]
[nanmean(TURNOILPRE)-nanmean(TURNOTHPRE) nanmean(TURNOILPOST)-nanmean(TURNOTHPOST) (nanmean(TURNOILPOST)-nanmean(TURNOILPRE))-(nanmean(TURNOTHPOST)-nanmean(TURNOTHPRE))]

%% compute ttests
[a b c d]=ttest2(TURNOILPRE,TURNOILPOST,[],[],'unequal')
[a b c d]=ttest2(TURNOTHPRE,TURNOTHPOST,[],[],'unequal')
[a b c d]=ttest2(TURNOILPRE,TURNOTHPRE,[],[],'unequal')
[a b c d]=ttest2(TURNOILPOST,TURNOTHPOST,[],[],'unequal')
%diff in diff
[a b c d]=ttest2((TURNOILPRE-TURNOTHPRE),(TURNOILPOST-TURNOTHPOST),[],[],'unequal')


